﻿@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService


<CnGalWebSite.Components.Containers.MasaTitleContainer Outline Title="@Title" Icon="@TitleIcon" Class="mb-4">
    <ButtonContent>
         <MButton Rounded Color="primary" OnClick="GetNewRandomList">
            <MIcon Left>mdi-refresh </MIcon>
            换一组
        </MButton>
    </ButtonContent>
    <ChildContent>
        <div class="row">
              @foreach (var item in Model)
            {
                <div class="@(IsTransverse?"col-12 col-lg-6 mb-4":"col-12 mb-4" )">
                    <NormalPerfectionCheckTipView Model="@item"></NormalPerfectionCheckTipView>
                </div>
            }

        </div>
    </ChildContent>

</CnGalWebSite.Components.Containers.MasaTitleContainer>

@code {

    public List<PerfectionCheckViewModel> Model { get; set; } = new List<PerfectionCheckViewModel>();

    [Parameter]
    public string Title { get; set; }
    [Parameter]
    public string TitleIcon { get; set; }
    [Parameter]
    public PerfectionCheckLevel Level { get; set; }
    [Parameter]
    public bool IsTransverse { get; set; }
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Model = await _httpService.GetAsync<List<PerfectionCheckViewModel>>("api/perfections/GetPerfectionCheckLevelRadomList/" + (int)Level);
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取随机词条完善度检查明细列表失败");
        }
    }


    public async Task GetNewRandomList()
    {
        await OnInitializedAsync();
    }
}
